package ycl.security.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ycl.common.constants.SecurityConstant;
import ycl.common.models.base.A;
import ycl.common.models.req.base.ObjReq;
import ycl.common.models.req.login.RegisterByMobilePassReq;
import ycl.common.models.res.LoginUser;
import ycl.common.result.Result;
import ycl.security.service.LoginService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 权限
 *
 * @author ycl
 * @date 2022/4/18 0018 13:06:31
 */
@Slf4j
@RestController
@RequestMapping(value = "/login", produces = SecurityConstant.CONTENT_TYPE)
@Api(tags = {"登录流程接口"})
public class LoginController {


	@Resource
	private LoginService loginService;

	@PostMapping("/login")
	@ApiOperation("登录")
	@ApiOperationSupport(order = 1)
	public Result<LoginUser> login(String username, String password) {
		return Result.badRequest(null);
	}


	@PostMapping("/wechat")
	@ApiOperation("微信登录")
	@ApiOperationSupport(order = 2)
	public Result<LoginUser> loginByWechatId(HttpServletRequest request, @NotNull @RequestBody @Valid ObjReq<String> req){
		LoginUser login = loginService.login(request, req.getObj());
		return Result.success(login);
	}


	@PostMapping(value = "/register/mobilePassword")
	@ApiOperation("用户名密码注册")
	@ApiOperationSupport(order = 11)
	public Result<A> registerByMobilePassword(@RequestBody @Valid RegisterByMobilePassReq req) {
		loginService.registerByMobilePassword(req);
		return Result.success();
	}


}
